package com.sunl.mall.ali.mq.model;

import com.aliyun.openservices.ons.api.SendResult;

public class RocketMqSendResult {
    private boolean success;
    private String messageId;
    private String topic;

    public RocketMqSendResult() {
    }

    public RocketMqSendResult(boolean success, String messageId, String topic) {
        this.success = success;
        this.messageId = messageId;
        this.topic = topic;
    }

    public static RocketMqSendResult successIfNotNull(SendResult sendResult) {
        if (sendResult != null) {
            return new RocketMqSendResult(true, sendResult.getMessageId(), sendResult.getTopic());
        }
        return fail();
    }

    private static final RocketMqSendResult FAIL_INSTANCE = new RocketMqSendResult(false, null, null) {
        public void setMessageId(String messageId) {
            throw new UnsupportedOperationException();
        }

        public void setSuccess(boolean success) {
            throw new UnsupportedOperationException();
        }

        public void setTopic(String topic) {
            throw new UnsupportedOperationException();
        }
    };

    public static RocketMqSendResult fail() {
        return FAIL_INSTANCE;
    }

    public boolean isSuccess() {
        return this.success;
    }
}